﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.HVAC.LevelIndependentTag;
using YArchitech.Revit;
using YRevitJig;

namespace YArchitech.HVAC.DuctTerminalTag
{
	public class DuctTerminalTagLinesJin : XUiJigBase
	{
		public XYZ StartPoint { get; set; }

		public DuctTerminalTagLinesJin(UIDocument uiDoc, double movingDistance, bool drawLineBox) : base(uiDoc)
		{
			this.view = uiDoc.Document.ActiveView;
			this.movingDistance = movingDistance;
			this.drawLineBox = drawLineBox;
		}

		public override void Draw(PaintEventArgs paintEventArgs)
		{
			base.Draw(paintEventArgs);
			if (!this.m_ptCur.IsEmpty && paintEventArgs != null)
			{
				try
				{
					this.resultLines.Clear();
					XYZ xyz = base.Client2Revit(this.m_ptCur);
					XYZ currentPoint = new XYZ(xyz.X, xyz.Y, this.StartPoint.Z);
					this.resultLines = (this.drawLineBox ? MarkDuctTerminalUtility.DrawLineBox(this.view, this.StartPoint, currentPoint, ref this.TagLocation, ref this.directionVector, this.movingDistance, this.tagContentChecked, ref this.verticalLineLength) : MarkDuctTerminalUtility.DrawNoLineBox(this.view, this.StartPoint, currentPoint, ref this.TagLocation, ref this.directionVector, this.movingDistance));
					XGraphics g = new XGraphics(paintEventArgs.Graphics, base.JigPen);
					foreach (Line curve in this.resultLines)
					{
						new XLine2D(base.Revit2Client(curve.GetEndPoint(0)), base.Revit2Client(curve.GetEndPoint(1))).Draw(g);
					}
				}
				catch (Exception ex)
				{
					ex.ToString();
				}
			}
		}

		public DirectionVector directionVector = new DirectionVector();

		public XYZ TagLocation;

		private Autodesk.Revit.DB.View view;

		public List<Line> resultLines = new List<Line>();

		private double movingDistance;

		private bool drawLineBox = true;

		public bool tagContentChecked;

		public double verticalLineLength;
	}
}
